package com.twq.types.othertype

/**
 * Created by tangweiqun on 2017/12/7.
 * 继承scala.Enumeration来实现一个枚举
 */
object Color extends Enumeration {
  val Red = Value("RED")
  val Green = Value
  val Blue = Value
}

object Direction extends Enumeration {
  val North, East, South, West = Value
}

object WeekDay extends Enumeration {
  type WeekDay = Value
  val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}


object Enumerations {
  def main(args: Array[String]): Unit = {
    Color.Blue
    Color.Green
    Color.Red

    import Color._
    Blue

    //1、以上三个枚举值的类型都是：Color.Value，是一个路径依赖类型
    //那么和Direction.Value的类型就不一样了

    //2、遍历枚举
    for (d <- Color.values) print(d + " ")

    //3、枚举的id是从0开始的
    Color.Red.id //0

    Color(0) //res4: Color.Value = Red


    //4、例子
    import WeekDay._

    def isWorkingDay(d: WeekDay) = !(d == Sat || d == Sun)

    WeekDay.values filter isWorkingDay foreach println
  }
}

